import React, { Component } from 'react'

export default class Far extends Component {
  state = {
    x: 0,
    y: 0,
  }

  handleMove = (e) => {
    // console.log(e)
    this.setState({
      x: e.clientX,
      y: e.clientY,
    })
  }

  componentDidMount() {
    window.addEventListener('mousemove', this.handleMove)
  }

  componentWillUnmount() {
    window.removeEventListener('mousemove', this.handleMove)
  }
  render() {
    // return this.props.render(this.state)
    // 组件子节点的内容其实也是props数据,只是属性名固定就叫做children
    return this.props.children(this.state)
  }
}
